//
//  ViewController.m
//  Share
//
//  Created by CPX on 2018/10/15.
//  Copyright © 2018年 CPX. All rights reserved.
//

#import "ViewController.h"
#import "ShareKit.h"
#import "LoginKit.h"
#import <TwitterKit/TWTRKit.h>

@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    CGRect f = self.view.frame;
    CGFloat w = f.size.width;
    CGFloat h = f.size.height;
    UITableView *table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, w, h) style:UITableViewStylePlain];
    table.delegate = self;
    table.dataSource = self;
    [table reloadData];
    [self.view addSubview:table];
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *identifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    if (indexPath.row == 0) {
        cell.textLabel.text = @"FaceBook 登录";
    }
    else if (indexPath.row == 1){
        cell.textLabel.text = @"Twitter 登录";
    }
    else if (indexPath.row == 2){
        cell.textLabel.text = @"Google 登录";
    }
    else if (indexPath.row == 3){
        cell.textLabel.text = @"FaceBook 分享";
    }
    else if (indexPath.row == 4){
        cell.textLabel.text = @"Twitter 分享";
    }
    else if (indexPath.row == 5){
        cell.textLabel.text = @"FaceBook 图片分享";
    }
    else if (indexPath.row == 6){
        cell.textLabel.text = @"Twitter 图片分享";
    }
    else if (indexPath.row == 7){
        cell.textLabel.text = @"FaceBook 从相册分享";
    }
    else if (indexPath.row == 8){
        cell.textLabel.text = @"Twitter 从相册分享";
    }
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 9;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        [LoginKit FBLoginWithSuccess:^(LoginResult * _Nonnull result) {
            
        } error:^(NSError * _Nullable error) {
            
        }];
    }
    else if (indexPath.row == 1){
        [LoginKit TwitterLoginWithSuccess:^(LoginResult * _Nonnull result) {
            
        } error:^(NSError * _Nullable error) {
            
        }];
    }
    else if (indexPath.row == 2){
        [LoginKit GoogleLoginWithSuccess:^(LoginResult * _Nonnull result) {
            
        } error:^(NSError * _Nullable error) {
            
        }];
    }
    else if (indexPath.row == 3){
        ShareItem *item = [ShareItem new];
        item.text = @"ggg";
        item.link = @"https://itunes.apple.com/us/app/id1402389078?mt=8";
        item.type = kShareItemTypeLink;
        
        [ShareKit shareWithType:kShareTypeFB item:item completion:^(NSError * _Nullable error, BOOL canceled) {
            
        }];
    }
    else if (indexPath.row == 4){
        ShareItem *item = [ShareItem new];
        item.text = @"ggg";
        item.link = @"https://itunes.apple.com/us/app/id1402389078?mt=8";
        item.type = kShareItemTypeLink;
        
        [ShareKit shareWithType:kShareTypeTwitter item:item completion:^(NSError * _Nullable error, BOOL canceled) {
            
        }];
    }
    else if (indexPath.row == 5){

        ShareItem *item = [ShareItem new];
        item.text = @"gggfff";
        item.link = @"https://itunes.apple.com/us/app/id1402389078?mt=8";
        item.type = kShareItemTypeImage;
        item.image = [UIImage imageNamed:@"testimg"];
        [ShareKit shareWithType:kShareTypeFB item:item completion:^(NSError * _Nullable error, BOOL canceled) {
            
        }];
    }
    else if (indexPath.row == 6){
        ShareItem *item = [ShareItem new];
        item.text = @"gggfff1";
        item.link = @"https://itunes.apple.com/us/app/id1402389078?mt=8";
        item.type = kShareItemTypeImage;
        item.image = [UIImage imageNamed:@"testimg"];
        [ShareKit shareWithType:kShareTypeTwitter item:item completion:^(NSError * _Nullable error, BOOL canceled) {
            
        }];
        
    }
    else if (indexPath.row == 7){
        ShareItem *item = [ShareItem new];
        item.text = @"gggfff";
        item.link = @"https://itunes.apple.com/us/app/id1402389078?mt=8";
        item.type = kShareItemTypePhoto;
        item.image = [UIImage imageNamed:@"testimg"];
        [ShareKit shareWithType:kShareTypeFB item:item completion:^(NSError * _Nullable error, BOOL canceled) {
            
        }];
    }
    else if (indexPath.row == 8){
        ShareItem *item = [ShareItem new];
        item.text = @"gggfff1";
        item.link = @"https://itunes.apple.com/us/app/id1402389078?mt=8";
        item.type = kShareItemTypePhoto;
        item.image = [UIImage imageNamed:@"testimg"];
        [ShareKit shareWithType:kShareTypeTwitter item:item completion:^(NSError * _Nullable error, BOOL canceled) {
            
        }];
    }
    
}

@end
